package com.group.Controller;
import cn.hutool.json.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.Enity.CarCharge;
import com.group.Service.CarChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

@Controller
@RequestMapping("carcharge")
public class CarChargeController {

    @Autowired
    private CarChargeService carChargeService;



    @ResponseBody
    @RequestMapping("queryCarchargeAll2")
    public String queryAllParkingCharge2(Integer page,Integer limit,Integer status){

        //System.out.println(status);
        PageHelper.startPage(page,limit);
        List<CarCharge> list = carChargeService.getCarCharges("",status);

        PageInfo pageInfo = new PageInfo<>(list);
        Long len = pageInfo.getTotal();
        List<CarCharge> list_new = pageInfo.getList();

        JSONObject json=new JSONObject();
        json.accumulate("count",len);
        json.accumulate("code",0);
        json.accumulate("msg","null");
        json.accumulate("data",list_new);
        return json.toString();
    }

    @ResponseBody
    @RequestMapping("initData")
    public JSONObject initData(@RequestBody JSONObject jsonObject){

        //System.out.println(jsonObject);
        CarCharge carCharge = new CarCharge();
        int money = jsonObject.getInt("money");
        int remarks = jsonObject.getInt("money");
        if (money < 1000000 && remarks < 1000000) {
            carCharge.setEndDate(jsonObject.getStr("endDate"));
            carCharge.setMoney(money);
            carCharge.setRemarks(remarks);
            carCharge.setPayDate(jsonObject.getStr("payDate"));
            carChargeService.initData(carCharge);
            JSONObject json=new JSONObject();
            json.accumulate("code",200);
            return json;
        }else{
            JSONObject json=new JSONObject();
            json.accumulate("code",500);
            json.accumulate("msg","你的钱太多了");
            return json;
        }

    }


}
